import time
from agno.tools import tool
from agno.agent import Agent
from agno.models.openai import OpenAIChat

@tool(requires_confirmation=True)
def sensitive_operation(data: str) -> str:
    """执行敏感操作，需要确认"""
    print("开始执行敏感操作")
    # 实现这里
    return "操作完成"

agent = Agent(
    model=OpenAIChat(
        id="qwen3",
        base_url="http://xai.dyg.com.cn/v1",
        api_key="dyg-y2fyntVOODsN7a1iNUgqjfh6dcBMfpciZWhn4KGJ1x8",
    ),
    tools=[sensitive_operation],
)

# Run the agent
run_response = agent.run("执行敏感操作", session_id=int(time.time()))

print(run_response.reasoning_content)
print(run_response.content)
print(run_response.is_paused)
print(run_response.tools_requiring_confirmation)
print(run_response.tools_requiring_user_input)
print(run_response.tools_requiring_user_input)

# Handle confirmation
if run_response.is_paused:
    for tool in run_response.tools_requiring_confirmation:
        # Get user confirmation
        print(f"工具 {tool.tool_name}({tool.tool_args}) 需要确认")
        confirmed = input(f"确定吗? (y/n): ").lower() == "y"
        tool.confirmed = confirmed

    # Continue execution
    response = agent.continue_run(run_response=run_response)